import { createApp } from 'vue'
import Antd from 'ant-design-vue';
import { createPinia } from 'pinia'
import { createI18n } from 'vue-i18n';

import 'ant-design-vue/dist/antd.css';
import '@/styles/normalize.less'
import '@/styles/base.less'
import '@/styles/animation.less'

import App from './App.vue'
import router from './router'

import enLocale from '@/locales/en.json'
import zhLocale from '@/locales/zh-CN.json'
import zhHKLocale from '@/locales/zh-HK.json'
import myLocale from '@/locales/my.json'
import { getLanguage } from "./utils";
import lazyDirective from '@/directives/lazy';

function isMobileDevice() {
  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
};

if (isMobileDevice()){
  const currentDomain = window.location.hostname;
  if (currentDomain === 'win183.com' || currentDomain === 'www.win183.com') {
    // 重定向到新域名
    window.location.href = 'https://m.win183.com';
  } else {
    window.location.href = "https://release.wabo-uni-m-frontend.pages.dev";
  }
}

const messages = {
  "en": enLocale,
  "zh-CN": zhLocale,
  "zh-HK": zhHKLocale,
  "my": myLocale,
  "zh": zhLocale
}
const curLanguage = getLanguage();
console.log(curLanguage)
const i18n = createI18n({
  legacy: false,
  locale: curLanguage, // 设置当前的语言环境
  messages, // 设置语言环境信息
})

const app = createApp(App)

app.directive('lazy', lazyDirective);

app.use(createPinia())
app.use(router)
app.use(Antd)
app.use(i18n);

app.mount('#app')
